home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11813 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  55 lines

  1. Path: inforamp.net!ts14-03
  2. From: rmorin@inforamp.net (Randy Charles Morin)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Object constuction in function call.
  5. Date: Sat, 16 Mar 96 09:21:10 GMT
  6. Organization: MiddleWorld SoftWare
  7. Message-ID: <4ie16n$pc1@sam.inforamp.net>
  8. References: <4icmqh$8g6@insosf1.netins.net>
  9. NNTP-Posting-Host: ts14-03.tor.inforamp.net
  10. X-Newsreader: News Xpress Version 1.0 Beta #4
  11.  
  12. In article <4icmqh$8g6@insosf1.netins.net>,
  13.    hhowe@trgnet.com (Harold Howe) wrote:
  14. >class TCorners
  15. >  {
  16. >  public:
  17. >    int w,x,y,z;
  18. >    TCorners( int a, int b, int c, int d) 
  19. >      { w=a;   x=b; y=c;  z=d;}
  20. >  } 
  21. >
  22. >void display_coordinates(TCorners corners)
  23. >  {
  24. >  cout << "corners are" << corners.w << corners.x
  25. >                        << corners.y << corners.z ;
  26. >  }
  27. >
  28. >int main(void)
  29. >  {
  30. >  display_coordinates(TCorners(1,1,20,10));
  31. >  display_coordinates(TCorners(1,5,25,15));
  32. >  display_coordinates(TCorners(2,5,20,10));
  33. >  }
  34.  
  35. The TCorners that you declare in main() are destroyed when you exit main.  
  36. Thus at the end of your program you have 0 objects.  Here's a procedure look 
  37. at what is happening.
  38.  
  39. int main(void)
  40. {
  41.     construct TCorners
  42.     display TCorners
  43.     construct TCorners
  44.     display TCorners
  45.     construct TCorners
  46.     display TCorners
  47.     destroy TCorners
  48.     destroy TCorners
  49.     destroy TCorners
  50. };
  51.  
  52. when the TCorners lose scope, then the destroy themselves.
  53.  
  54. Agrivar
  55.